package com.lxc.infrastructure.persistent.repository;

import com.lxc.domain.register.model.entity.ApplicationInterfaceEntity;
import com.lxc.domain.register.model.entity.ApplicationInterfaceMethodEntity;
import com.lxc.domain.register.model.entity.ApplicationSystemEntity;
import com.lxc.domain.register.repository.IRegisterManageRepository;
import com.lxc.infrastructure.persistent.dao.IApplicationInterfaceDao;
import com.lxc.infrastructure.persistent.dao.IApplicationInterfaceMethodDao;
import com.lxc.infrastructure.persistent.dao.IApplicationSystemDao;
import com.lxc.infrastructure.persistent.dao.IGatewayDistributionDao;
import com.lxc.infrastructure.persistent.po.ApplicationInterface;
import com.lxc.infrastructure.persistent.po.ApplicationInterfaceMethod;
import com.lxc.infrastructure.persistent.po.ApplicationSystem;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author lxc18
 * @date 2024/12/19 15:58
 * @description RegisterManageRepository
 */
@Repository
public class RegisterManageRepository implements IRegisterManageRepository {
    @Resource
    IApplicationInterfaceMethodDao applicationInterfaceMethodDao;
    @Resource
    IApplicationInterfaceDao applicationInterfaceDao;
    @Resource
    IApplicationSystemDao applicationSystemDao;

    @Resource
    IGatewayDistributionDao gatewayDistributionDao;
    @Override
    public void registerApplicationInterface(ApplicationInterfaceEntity applicationInterfaceEntity) {
        ApplicationInterface applicationInterface = new ApplicationInterface();
        applicationInterface.setSystemId(applicationInterfaceEntity.getSystemId());
        applicationInterface.setInterfaceId(applicationInterfaceEntity.getInterfaceId());
        applicationInterface.setInterfaceName(applicationInterfaceEntity.getInterfaceName());
        applicationInterface.setInterfaceVersion(applicationInterfaceEntity.getInterfaceVersion());
        applicationInterfaceDao.insert(applicationInterface);
    }

    @Override
    public void registerApplicationInterfaceMethod(ApplicationInterfaceMethodEntity applicationInterfaceMethodEntity) {
        ApplicationInterfaceMethod applicationInterfaceMethod = new ApplicationInterfaceMethod();
        applicationInterfaceMethod.setSystemId(applicationInterfaceMethodEntity.getSystemId());
        applicationInterfaceMethod.setInterfaceId(applicationInterfaceMethodEntity.getInterfaceId());
        applicationInterfaceMethod.setMethodId(applicationInterfaceMethodEntity.getMethodId());
        applicationInterfaceMethod.setMethodName(applicationInterfaceMethodEntity.getMethodName());
        applicationInterfaceMethod.setParameterType(applicationInterfaceMethodEntity.getParameterType());
        applicationInterfaceMethod.setUri(applicationInterfaceMethodEntity.getUri());
        applicationInterfaceMethod.setHttpCommandType(applicationInterfaceMethodEntity.getHttpCommandType());
        applicationInterfaceMethod.setAuth(applicationInterfaceMethodEntity.getAuth());
        applicationInterfaceMethodDao.insert(applicationInterfaceMethod);

    }

    @Override
    public void registerApplicationSystem(ApplicationSystemEntity applicationSystemEntity) {
        ApplicationSystem applicationSystem = new ApplicationSystem();
        applicationSystem.setSystemId(applicationSystemEntity.getSystemId());
        applicationSystem.setSystemName(applicationSystemEntity.getSystemName());
        applicationSystem.setSystemType(applicationSystemEntity.getSystemType());
        applicationSystem.setSystemRegistry(applicationSystemEntity.getSystemRegistry());
        applicationSystemDao.insert(applicationSystem);


    }

    @Override
    public String getGatewayIdBySystemId(String systemId) {
        return gatewayDistributionDao.getGatewayIdBySystemId(systemId);
    }
}
